package com.shhic.hhplt.server.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
/**
 * XML日期格式工具
 * @author 张文硕
 *
 */
public class XMLDateUtil {
	public static XMLGregorianCalendar convertToXMLGregorianCalendar(Date date) {

		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(date);
		XMLGregorianCalendar gc = null;
		try {
			gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
		} catch (Exception e) {

			e.printStackTrace();
		}
		return gc;
	}

	public static long convertToDate(XMLGregorianCalendar cal){
		GregorianCalendar ca = cal.toGregorianCalendar();
		return ca.getTime().getTime();
	}

	public static String convertToString(XMLGregorianCalendar value) {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(convertToDate(value));
	}

}
